package com.heima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.heima.reggie.bean.AddressBook;
import com.heima.reggie.mapper.AddressMapper;
import com.heima.reggie.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AddressBookServiceImpl implements AddressBookService {
    @Autowired
    private AddressMapper mapper;
    @Override
    public void save(AddressBook addressBook) {
        mapper.insert(addressBook);
    }
    @Override
    public void update(LambdaUpdateWrapper<AddressBook> wrapper) {
        mapper.update(null, wrapper);
    }

    @Override
    public void updateById(AddressBook addressBook) {
        mapper.updateById(addressBook);
    }

    @Override
    public AddressBook getById(Long id) {
        return mapper.selectById(id);
    }

    @Override
    public AddressBook getOne(LambdaQueryWrapper<AddressBook> queryWrapper) {
        return mapper.selectOne(queryWrapper);
    }

    @Override
    public List<AddressBook> list(LambdaQueryWrapper<AddressBook> queryWrapper) {
        return mapper.selectList(queryWrapper);
    }

    @Override
    public void deleteById(long id) {
        mapper.deleteById(id);
    }

    @Override
    public AddressBook getByUid(long uid) {
        return mapper.selectOne(new LambdaQueryWrapper<AddressBook>().eq(AddressBook::getUserId,uid).eq(AddressBook::getIsDefault,1));
    }

}
